package com.ll.studentservice.controller;


import com.ll.commonUtils.MD5;
import com.ll.commonUtils.R;
import com.ll.studentservice.entity.EduDepartment;
import com.ll.studentservice.entity.EduStudent;
import com.ll.studentservice.entity.vo.AddStudent;
import com.ll.studentservice.service.EduDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2020-11-26
 */
@Api(description = "系信息增删改查API") //swagger界面提示
@RestController
@RequestMapping("/studentservice/edudepartment")
public class EduDepartmentController {
    @Autowired
    private EduDepartmentService eduDepartmentService;

    @ApiOperation("添加系信息")
    @PostMapping("addDepartment")
    public R addDepartment(@RequestBody EduDepartment eduDepartment) {

        boolean save = eduDepartmentService.save(eduDepartment);

        //三元运算符
        return save ? R.ok() : R.error();
    }

    @ApiOperation("查询所有系信息")
    @GetMapping("findAllDepartment")
    public R findAllDepartment() {
        List<EduDepartment> departments = eduDepartmentService.list(null);
        return R.ok().data("allDepartment", departments);
    }

    @ApiOperation("查询单个系")
    @GetMapping("findOneDepartment/{departmentId}")
    public R findOneDepartment(@PathVariable String departmentId) {
        EduDepartment eduDepartment = eduDepartmentService.getById(departmentId);
        if (StringUtils.isEmpty(eduDepartment)){
            return R.error().message("没有这个系的信息");
        } else {
            return R.ok().data("item", eduDepartment);
        }
    }

    @ApiOperation("删除系信息")
    @DeleteMapping("delteDepartmentById/{departmentId}")
    public R delteDepartmentById(@PathVariable String departmentId) {
        boolean b = eduDepartmentService.removeById(departmentId);
        return b ? R.ok() : R.error();
    }

    @ApiOperation("修改系信息")
    @PostMapping("updateDepartmentById")
    public R updateDepartmentById(@RequestBody EduDepartment eduDepartment) {
        boolean b = eduDepartmentService.updateById(eduDepartment);
        return b ? R.ok() : R.error();
    }




}

